<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="会员编号" prop="customerNo">
        <el-input
          v-model="queryParams.customerNo"
          placeholder="请输入会员编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付流水号" prop="payFlowNo">
        <el-input
          v-model="queryParams.payFlowNo"
          placeholder="请输入支付流水号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          v-hasPermi="['finance:activity:query']"
          >查询</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['finance:activity:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="list">
      <el-table-column
        min-width="120"
        label="活动名称"
        align="center"
        prop="activityName"
        show-overflow-tooltip
      />
      <el-table-column
        min-width="120"
        label="支付流水号"
        align="center"
        prop="payFlowNo"
        show-overflow-tooltip
      />
      <el-table-column
        min-width="120"
        label="支付方式"
        align="center"
        prop="payType"
      >
        <template slot-scope="scope">
          {{ scope.row.payType | typeFilter(dict.type.finance_payType) }}
        </template>
      </el-table-column>
      <el-table-column
        min-width="100"
        label="支付金额"
        align="center"
        prop="paidAmount"
      />
      <el-table-column
        min-width="100"
        label="支付状态"
        align="center"
        prop="payStatus"
      >
        <template slot-scope="scope">
          {{ scope.row.payStatus | typeFilter(dict.type.finance_payStatus) }}
        </template>
      </el-table-column>
      <el-table-column
        min-width="160"
        label="支付完成时间"
        align="center"
        prop="paidTime"
        sortable
      />
      <el-table-column
        min-width="160"
        label="会员编号"
        align="center"
        prop="customerNo"
        show-overflow-tooltip
      />
      <el-table-column
        min-width="160"
        label="业务编号"
        align="center"
        prop="orderNo"
        show-overflow-tooltip
      />
      <el-table-column
        min-width="160"
        label="买家账号"
        align="center"
        prop="buyerAccount"
        show-overflow-tooltip
      />
      <el-table-column
        min-width="120"
        label="买家姓名"
        align="center"
        prop="memberName"
      />
      <el-table-column
        min-width="120"
        label="买家电话"
        align="center"
        prop="memberPhone"
      />
      <el-table-column
        min-width="100"
        label="操作"
        align="center"
        fixed="right"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handDetail(scope.row)"
            >详情</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {
  getOrderPaymentRecordList,
  exportOrderPaymentRecord,
} from '@/api/finance/activity'

export default {
  name: 'FinanceActive',
  components: {},
  dicts: ['finance_payType', 'finance_payStatus'],
  data() {
    return {
      showSearch: true,
      // 表格遮罩
      loading: false,
      // 表格数据
      list: [],
      total: 1,
      // 导出遮罩层
      exportLoading: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        customerNo: '',
        payFlowNo: '',
      },
    }
  },
  filters: {
    typeFilter(val, type) {
      if (val === null) return null
      let data = type.filter((item) => {
        return val == item.value
      })
      if (data.length) {
        return data[0].label
      } else {
        return val
      }
    },
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询租户管理列表 */
    getList() {
      this.loading = true
      getOrderPaymentRecordList(this.queryParams).then((response) => {
        this.list = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    /** 详情按钮操作 */
    handDetail(row) {
      this.$router.push({
        path: '/finance/activity/detail/' + row.paymentRecordId,
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = {
        customerNo: this.queryParams.customerNo,
        payFlowNo: this.queryParams.payFlowNo,
      }
      this.$modal
        .confirm('是否确认导出活动订单流水数据项？')
        .then(() => {
          this.exportLoading = true
          exportOrderPaymentRecord(queryParams)
            .then((res) => {
              this.$download.name(res.msg)
              this.exportLoading = false
            })
            .catch((err) => {
              this.exportLoading = false
            })
        })
        .catch(() => {})
    },
  },
}
</script>
